﻿@model Zor_Web.Models.Base.V_Zor_TenantEnterprise
@using Webdiyer.WebControls.Mvc;
@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>企业租户管理</title>
    <link href="~/Content/LayerUI/src/css/layui.css" rel="stylesheet" />
    <link href="~/Content/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <link href="~/Content/Styles/zor.css" rel="stylesheet" />
    <!-- 框架必要 -->
    <script src="~/Content/Scripts/jquery/jquery-1.9.1.min.js"></script>
    <script src="~/Content/Scripts/learunui-framework.js"></script>
    <script src="~/Content/Scripts/Zor_AJax.js"></script>
    <!-- 消息提示 -->
    <script language='javascript' src='~/Content/layer/layer.js'></script>
    <!-- 表单验证 -->
    <script src="~/Content/Scripts/JValidator.js"></script>
</head>
<body class="gray-bg">
    <div class="layui-tab layui-tab-brief main-tab-container ">

        <div class="col-sm-12 ct-padding">
            <div class="col-sm-8 ct-padding">
                <button id="btnAdd" class="layui-btn layui-btn layui-btn-small"><span class="glyphicon glyphicon-plus"></span> 新增</button>
                <button id="btnUpdate" class="layui-btn layui-btn-warm layui-btn-small"><span class="glyphicon glyphicon-pencil"></span> 编辑</button>
                <button id="btnDelete" class="layui-btn layui-btn-danger layui-btn-small"><span class="glyphicon glyphicon-trash"></span> 删除</button>
                <button id="btnSearchFull" class="layui-btn  layui-btn-normal layui-btn-small"><span class="glyphicon glyphicon-search"></span>查询</button>
                <button id="btnMessage" class="layui-btn layui-btn-orchid layui-btn-small"><span class="glyphicon glyphicon-list-alt"></span>详情</button>
                <button id="btnExport" class="layui-btn layui-btn-springgreen  layui-btn-small"><span class="glyphicon glyphicon-arrow-down"></span>导出</button>
                <button id="btnRefresh" class="layui-btn layui-btn-blue layui-btn-small"><span class="glyphicon glyphicon-repeat"></span>刷新</button>
            </div>
        </div>
        <div class="col-sm-12  layui-tab-content">
            <div class="mail-box" style="overflow-x:scroll;white-space:nowrap;">
                <table class="layui-table" lay-skin="line">
                    <thead>
                        <tr>
                            <th hidden></th>
                            <th></th>
                            <th>公司名称</th>
                            <th>联系电话</th>
                            <th>办理税证</th>
                            <th>税务登记号</th>
                            <th>管理代码</th>
                            <th>法人</th>
                            <th>税务机关</th>
                            <th>经营范围</th>
                            <th>所属行业</th>
                        </tr>
                    </thead>
                    <tbody id="accordion">
                        @foreach (var item in Model.PageData)
                        {
                            <tr>
                                <td hidden>@item.Tenant_Id</td>
                                <td><input type="radio" name="chk" id="@item.Tenant_Id" value="@item.Tenant_Id" /></td>
                                <td>@item.Tenant_Name</td>
                                <td>@item.Tenant_Phone</td>
                                <td>@item.istaxregistration</td>
                                <td>@item.Tenant_TaxRegistrationNum</td>
                                <td>@item.Tenant_Code</td>
                                <td>@item.Tenant_LegalPerson</td>
                                <td>@item.Tenant_TaxAuthority</td>
                                <td>@item.Tenant_ScopeBusiness</td>
                                <td>@item.industry</td>
                                <td hidden>@item.Ept_Industry</td>
                                <td hidden>@item.Tenant_IsTaxRegistration</td>
                                <td hidden>@item.Tenant_Note</td>
                            </tr>
                        }

                    </tbody>
                </table>
                <div class="col-sm-12">
                    <div class="col-sm-10">
                        @Html.Pager(Model.PageData, new PagerOptions { PageIndexParameterName = "index", ContainerTagName = "ul", PrevPageText = "上页", NextPageText = "下页", FirstPageText = "首页", LastPageText = "尾页", CssClass = "pagination", PagerItemsSeperator = "", CurrentPagerItemWrapperFormatString = "<li class=\"active\"><a href=\"#\">{0}</a></li>", PagerItemWrapperFormatString = "<li>{0}</li>" }, new { id = "bootstrappager", @class = "pagination" })
                    </div>
                    <div class="col-sm-2 to-righjt">
                        共 @Model.PageData.TotalItemCount 条记录，页 @Model.PageData.CurrentPageIndex/@Model.PageData.TotalPageCount
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 默认模态 -->
    <div id="myModal" hidden data-backdrop="static">
        <div id="divfrom" class="layui-tab-content">
            <form method="get" class="form-horizontal m-t">
                <div class="layui-form-item" hidden>
                    <label class="col-sm-3 layui-form-label">租户Id：</label>
                    <div class="col-sm-8">
                        <input id="Tenant_Id" type="text" class="form-control">
                        <input id="Tenant_Type" type="text" class="form-control" value="2">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">公司名称：</label>
                    <div class="col-sm-4">
                        <input id="Tenant_Name" type="text" class="form-control" placeholder="请输入公司名称" autofocus="autofocus" datacol="yes" err="公司名称" checkexpession="NotNull">
                    </div>
                    <label class="col-sm-2 layui-form-label f12">
                        <nobr>税务登记证：</nobr>
                    </label>
                    <div class="col-sm-4">
                        <select name="temp" class="form-control" id="Tenant_IsTaxRegistration">
                            <option value="1">未办</option>
                            <option value="2">已办</option>
                        </select>
                    </div>
                </div>
               
                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">税务登记号：</label>
                    <div class="col-sm-4">
                        <input id="Tenant_TaxRegistrationNum" type="text" class="form-control" placeholder="请输入税务登记号" autofocus="autofocus" datacol="yes" err="税务登记号" checkexpession="NotNull">
                    </div>
                    <label class="col-sm-2 layui-form-label">管理代码：</label>
                    <div class="col-sm-4">
                        <input id="Tenant_Code" type="text" class="form-control" placeholder="请输入管理代码" autofocus="autofocus" datacol="yes" err="管理代码" checkexpession="NotNull">
                    </div>
                </div>
               
                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">法人：</label>
                    <div class="col-sm-4">
                        <input id="Tenant_LegalPerson" type="text" class="form-control" placeholder="请输入法人" autofocus="autofocus" datacol="yes" err="法人" checkexpession="NotNull">
                    </div>
                    <label class="col-sm-2 layui-form-label">联系电话：</label>
                    <div class="col-sm-4">
                        <input id="Tenant_Phone" type="text" class="form-control" placeholder="请输入电话号码" autofocus="autofocus" datacol="yes" err="联系电话" checkexpession="MobileOrPhone">
                    </div>
                </div>
               
                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">税务机关：</label>
                    <div class="col-sm-4">
                        <input id="Tenant_TaxAuthority" type="text" class="form-control" placeholder="请输入税务机关" autofocus="autofocus" datacol="yes" err="税务机关" checkexpession="NotNull">
                    </div>
                    <label class="col-sm-2 layui-form-label">
                        <nobr>所属行业：</nobr>
                    </label>
                    <div class="col-sm-4">
                        <select name="temp" class="form-control" id="Ept_Industry"></select>
                    </div>
                </div>
               
                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">经营范围：</label>
                    <div class="col-sm-4">
                        <textarea id="Tenant_ScopeBusiness" class="form-control" cols="30" rows="4" placeholder="请输入税务机关" autofocus="autofocus" datacol="yes" err="经营范围" checkexpession="NotNull"></textarea>
                    </div>  
                    <label class="col-sm-2 layui-form-label">备注：</label>
                    <div class="col-sm-4">
                        <textarea id="Tenant_Note" class="form-control" cols="20" rows="4" placeholder="请输入备注" autofocus="autofocus"></textarea>
                    </div>                 
                </div>              
            </form>                    
            <div class="box-footer">
                <button id="btnSure" class="btn btn-info pull-right">
                    <i class="fa fa-check"></i>提交
                </button>
            </div>
            
        </div>
    </div>

    <!--查询-->
    @using (Html.BeginForm("Zor_TenantEnterprise", "Base", new RouteValueDictionary { { "Model", Model } }, FormMethod.Get))
    {
        <!-- 查询模态框 -->
    <div id="myModalSearch" hidden data-backdrop="static">
        <div id="divfrom" class="layui-tab-content">           
                <div class="form-horizontal">
                    <div class="layui-form-item">
                        <label class="col-sm-2 layui-form-label">公司名称：</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" name="Tenant_Name" value="@Model.Tenant_Name">
                        </div>
                        <label class="col-sm-2 layui-form-label">联系电话：</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" name="Tenant_Phone" value="@Model.Tenant_Phone">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="col-sm-2 layui-form-label">办理税证：</label>
                        <div class="col-sm-4">
                            <select name="istaxregistration" class="form-control">
                                <option value="">全部</option>
                                <option value="@Model.istaxregistration">已办</option>
                                <option value="@Model.istaxregistration">未办</option>
                            </select>
                        </div>
                        <label class="col-sm-2 layui-form-label">税务登记号：</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" name="Tenant_TaxRegistrationNum" value="@Model.Tenant_TaxRegistrationNum">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="col-sm-2 layui-form-label">管理代码：</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" name="Tenant_Code" value="@Model.Tenant_Code">
                        </div>
                        <label class="col-sm-2 layui-form-label">法人：</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" name="Tenant_LegalPerson" value="@Model.Tenant_LegalPerson">
                        </div>
                    </div>
                </div>
                <div class="box-footer">
                    <button type="submit" class="btn btn-info pull-right">
                        <i class="fa fa-search"></i>查询
                    </button>
                </div>
        </div>
    </div>
              
    }

    <!-- 导出模态 -->
    <form action="/Base/ExportTenantEnterprise" enctype="multipart/form-data" method="post" id="formDownload">
        <div id="exportHtml" style="display:none;">
            <div class="eh_wrap">
                <div class="eh_head">
                    <p style="">请选择您要导出的数据列</p>
                </div>
                <table width="100%" cellpadding="5" cellspacing="0">
                    <tr>
                        <td><input id="Tenant_Name" type="checkbox" value="公司名称" name="chk_list" checked="checked" /><label>公司名称</label></td>
                        <td><input id="Tenant_Phone" type="checkbox" value="联系电话" name="chk_list" checked="checked" /><label>联系电话</label></td>
                        <td><input id="istaxregistration" type="checkbox" value="办理税证" name="chk_list" checked="checked" /><label>办理税证</label></td>
                        <td><input id="Tenant_TaxRegistrationNum" type="checkbox" value="税务登记号" name="chk_list" checked="checked" /><label>税务登记号</label></td>
                    </tr>
                    <tr>
                        <td><input id="Tenant_Code" type="checkbox" value="管理代码" name="chk_list" checked="checked" /><label>管理代码</label></td>
                        <td><input id="Tenant_LegalPerson" type="checkbox" value="法人" name="chk_list" checked="checked" /><label>法人</label></td>
                        <td><input id="Tenant_TaxAuthority" type="checkbox" value="税务机关" name="chk_list" checked="checked" /><label>税务机关</label></td>
                        <td><input id="Tenant_ScopeBusiness" type="checkbox" value="经营范围" name="chk_list" checked="checked" /><label>经营范围</label></td>
                    </tr>
                    <tr>
                        <td><input id="industry" type="checkbox" value="所属行业" name="chk_list" checked="checked" /><label>所属行业</label></td>
                    </tr>
                </table>
            </div>
            <div class="box-footer">
                <button type="submit" id="btnExportSure" class="btn btn-info pull-right">
                    <i class="fa fa-repeat"></i>导出
                </button>
                <input type="hidden" id="fields" name="fields" value="" />
                <input type="hidden" id="where" name="where" value="and Tenant_Type=2" />
            </div>
        </div>
    </form>
    <!-- 详情模态 -->
    <div id="myModalDetails" hidden data-backdrop="static">
        <div id="divfrom" class="layui-tab-content">
        
                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">公司名称：</label>
                    <div class="col-sm-4 layui-input" id="Tenant_Names"></div>
                    <label class="col-sm-2 layui-form-label f12">税务登记证：</label>
                    <div class="col-sm-4 layui-input" id="Tenant_IsTaxRegistrations"></div>
                </div>

                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">税务登记号：</label>
                    <div class="col-sm-4 layui-input" id="Tenant_TaxRegistrationNums"></div>
                    <label class="col-sm-2 layui-form-label">管理代码：</label>
                    <div class="col-sm-4 layui-input" id="Tenant_Codes"></div>
                </div>

                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">法人：</label>
                    <div class="col-sm-4 layui-input" id="Tenant_LegalPersons"></div>
                    <label class="col-sm-2 layui-form-label">联系电话：</label>
                    <div class="col-sm-4 layui-input" id="Tenant_ProprietorPhones"></div>
                </div>

                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">税务机关：</label>
                    <div class="col-sm-4 layui-input" id="Tenant_TaxAuthoritys"></div>
                    <label class="col-sm-2 layui-form-label">所属行业：</label>
                    <div class="col-sm-4 layui-input" id="Ept_Industrys"></div>
                </div>

                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">经营范围：</label>
                    <div class="col-sm-4 layui-input" id="Tenant_ScopeBusinesss"></div>
                    <label class="col-sm-2 layui-form-label">备注：</label>
                    <div class="col-sm-4 layui-input" id="Tenant_Notes"></div>
                </div>
           
        </div>
    </div>

    <script type="text/javascript">

        $(function () {

           
            /*刷新*/

            $("#btnRefresh").click(function () {
                Replace();
            });

            /*全选*/

            $("#cbkCheckAll").click(function () {
                if (this.checked) {
                    $("input[name='chk']").prop('checked', true);
                } else {
                    $("input[name='chk']").prop('checked', false);
                }
            });

            /*查询*/

            $("#btnSearchFull").click(function () {
                LayerOpen('740px', '250px', '查询', $('#myModalSearch'));
            });

            /*增加企业租户*/
            $("#btnAdd").click(function () {               
                GetIndustry(); //所有行业
                LayerOpen('750px', '400px', '企业租户新增', $('#myModal'));
            });

            /*修改企业租户*/
            $("#btnUpdate").click(function () {
                var checkId = CheckboxValueIDs();              
                if (checkId.length == 0) {
                    layer.msg("请选择要修改的信息！");                 
                    return;
                }
                if (checkId.length > 1) {
                    layer.msg("仅可选择一行信息修改！");
                    return;
                }
                GetIndustry();                                     //所有行业              
                $("#Tenant_Id").val(checkId[0]);
                $("#Tenant_Name").val(getTableCell(2));
                $("#Tenant_Phone").val(getTableCell(3));
                $("#Tenant_TaxRegistrationNum").val(getTableCell(5));
                $("#Tenant_Code").val(getTableCell(6));
                $("#Tenant_LegalPerson").val(getTableCell(7));
                $("#Tenant_TaxAuthority").val(getTableCell(8));
                $("#Tenant_ScopeBusiness").val(getTableCell(9));
                $("#Ept_Industry").val(getTableCell(11));
                $("#Tenant_IsTaxRegistration").val(getTableCell(12));
                $("#Tenant_Note").val(getTableCell(13));
                LayerOpen('750px', '400px', '企业租户修改', $('#myModal'));
            });

            /*删除租户*/
            $("#btnDelete").click(function () {
                var checkId = CheckboxValueIDs();
                if (checkId.length == 0) {
                    layer.msg("请选择要删除的租户！");                                                             //未选中任何行
                    return;
                }
                else {
                    layer.confirm("确定要删除吗?", { icon: 2, btn: ['确定', '取消'] }, function () {
                        ZorPostSimpleData("/Base/DeleteTenant", JSON.stringify({ 'Id': checkId }), function (data) { //获取数据(带参数)
                            layer.msg(data.AnswerMeg, function () {
                                layer.closeAll();
                                Replace();
                            });
                        })
                    })
                }
            });

            /*保存*/
            $("#btnSure").click(function () {

                if (!CheckDataValid('.form-horizontal')) {
                    return false;
                }
                var JsData = GetWebControls(divfrom);
                ZorPostSimpleData("/Base/AddAlterTenant", JSON.stringify({ "tenant": JsData }), function (data) {
                    layer.msg(data.AnswerMeg, function () {
                        layer.closeAll();
                        Replace();
                    });
                });

            });

            /*导出*/

            $("#btnExport").click(function () {
                layer.open({
                    type: 1,
                    title: '导出提示',
                    shade: false,
                    skin: 'layui-layer-rim',
                    area: ['620px', '280px'], //宽高
                    content: $('#exportHtml')
                });
            });

            /*导出交互*/

            $("#btnExportSure").click(function () {
                var arr = new Array();
                $("[name='chk_list']").each(function () {
                    if ($(this).is(":checked")) {
                        arr.push($(this).attr("id") + "|" + $(this).val());
                    }
                });
                $("#fields").val(arr);
                document.getElementById('formDownload').submit();
                layer.closeAll();
            });

            /*详情*/

            $("#btnMessage").click(function () {
                var checkId = CheckboxValueIDs();              
                if (checkId.length == 0) {
                    layer.msg("请选择要查看的信息！");                 
                    return;
                }
                if (checkId.length > 1) {
                    layer.msg("仅可选择一行信息查看！");                   
                    return;
                }
                LayerOpen('720px', '330px', '企业租户详情', $('#myModalDetails'));
                $("#Tenant_Names").html(getTableCell(2));
                $("#Tenant_ProprietorPhones").html(getTableCell(3));
                $("#Tenant_TaxRegistrationNums").html(getTableCell(5));
                $("#Tenant_Codes").html(getTableCell(6));
                $("#Tenant_LegalPersons").html(getTableCell(7));
                $("#Tenant_TaxAuthoritys").html(getTableCell(8));
                $("#Tenant_ScopeBusinesss").html(getTableCell(9));
                $("#Ept_Industrys").html(getTableCell(10));
                $("#Tenant_IsTaxRegistrations").html(getTableCell(4));
                $("#Tenant_Notes").html(getTableCell(13));
            });


        });

        /**
        * 查询所有行业
        */
        function GetIndustry() {
            var html = "";
            getAjax("/Base/SelectIndustry", "", function (data) {
                accordionJson = eval("(" + data + ")");
                $.each(accordionJson, function (i) {
                    var nbsp = ""
                    html += "<option value='" + accordionJson[i].CommonType_ID + "' >" + nbsp + accordionJson[i].CommonType_Name + "</option>";
                });
            });
            $("#Ept_Industry").empty().append(html);
        }

    </script>
</body>

</html>

